package com.neusoft.his.sb.controller;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

import org.apache.tomcat.jni.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.his.sb.entity.CommonResult;
import com.neusoft.his.sb.entity.Dept;
import com.neusoft.his.sb.service.DeptService;

@RestController
@RequestMapping("/dept")
@CrossOrigin("*")
public class DeptController {

	@Autowired
	DeptService deptService;

	public void setDeptService(DeptService deptService) {
		this.deptService = deptService;
	}
	 
	

	/// dept/mod
	@PostMapping("/mod")
	/**
	 * 实现根据ID只修改部门名称或者地址或者两者同时修改
	 * 
	 * @param dept
	 * @return
	 */
	public CommonResult modDept1(@RequestBody Dept dept) {
		System.out.println("DeptController.getByPrefixName()"+ dept.toString());
		
		CommonResult result = new CommonResult<Dept>(dept);
		return result;
	}

	/// dept/mod
	@PostMapping("/mod1")
	/**
	 * 实现根据ID只修改部门名称或者地址或者两者同时修改
	 * 
	 * @param dept
	 * @return
	 */
	public CommonResult modDept(@RequestBody Dept dept) {
		System.out.println("DeptController.getByPrefixName()");
		CommonResult result = deptService.modDept(dept);
		return result;
	}

	// /dept/prefix/{prefixname}
	@GetMapping("/prefix/{prefixname}")
	public CommonResult getByPrefixName(@PathVariable("prefixname") String prefixname) {
		System.out.println("DeptController.getByPrefixName()");
		CommonResult result = deptService.getByPrefixName(prefixname);
		return result;
	}

	@GetMapping("/{deptno}")
	public CommonResult getById(@PathVariable("deptno") int deptno) {
		System.out.println("DeptController.getById()");
		CommonResult result = deptService.getById(deptno);
		return result;
	}

	@GetMapping("/all")
	public CommonResult getAll() {

		System.out.println("DeptController.getById()");
		CommonResult result = deptService.getAll();
		return result;
	}

	@PutMapping("/add")
	public CommonResult addDept(@RequestBody Dept dept) {
		System.out.println(dept);
		// CommonResult result =  deptService.addDept(dept);
		CommonResult result = new CommonResult<Dept>(dept);
		return result;
	}
}
